
const int buttonPin = 3;
const int xPin = 12; // X input from accelerometer
const int yPin = 11; // Y input accelerometer

void setup() {
  Serial.begin(38400);
  pinMode(xPin, INPUT);
  pinMode(yPin, INPUT);
  pinMode(buttonPin, INPUT);
}

void loop() {
  
  const uint32_t timeout_us = 20000;
  
  int xPulse, yPulse; // read from accelerometer
  int xVal, yVal; // converted value
  
  // read x &amp; y values
  xPulse = pulseIn(xPin,timeout_us);
  yPulse = pulseIn(yPin,timeout_us);
  
  xVal = ((xPulse / 10) - 500) * 8;
  yVal = ((yPulse / 10) - 500) * 8;
  
  //Serial.print(analogRead(0));
  //Serial.print("\t");
  
  Serial.print("#\t");  
  Serial.print(xVal);
  Serial.print("\t");
  Serial.print(yVal);
  Serial.print(digitalRead(buttonPin));
  Serial.print("\t");
  Serial.println();
  
  delay(300);
}


